#!/usr/bin/python2.6
# -*- coding: utf-8 -*-

import pprint
from xml.etree import ElementTree as ET
import wixml

def test1():
    ###
    obj = [ 10,
            'Hello',
            u'привет',
            [1, 'hi!', 123.45],
            {'a': 1, 'b': 2}
          ]
    root = wixml.ObjectToXmlDoc(obj)
    s = ET.tostring(root)
    wixml.XmlPrettyPrint(s)

    ###
    obj = wixml.XmlDocToObject(root)

    pp = pprint.PrettyPrinter(indent=4)
    pp.pprint(obj)

def test2():
    pp = pprint.PrettyPrinter()

    print '---------------------------------------------'
    print 'Creating request'
    args = { 'a': 5,
             'b': 7 }
    xmlDoc = wixml.CreateXmlRequest('Add', args)
    wixml.XmlPrettyPrint(ET.tostring(xmlDoc))

    print '---------------------------------------------'
    print 'Parsing request'
    obj = wixml.ParseXmlRequest(xmlDoc)
    pp.pprint(obj)

    print '---------------------------------------------'
    print 'Creating response'
    data = 'some data'
    xmlDoc = wixml.CreateXmlResponse('ok', data)
    wixml.XmlPrettyPrint(ET.tostring(xmlDoc))

    print '---------------------------------------------'
    print 'Parsing response'
    obj = wixml.ParseXmlResponse(xmlDoc)
    pp.pprint(obj)

def main():
    print 'xml_test v0.1'
    #test1()
    test2()

if __name__ == '__main__':
    main()
